package com.duobao.view;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.*;

import javax.swing.*;

import com.duobao.game.DuobaoSwingLaunch;
import com.duobao.server.Map;
import com.duobao.server.Maps;
import com.duobao.uitl.myFont;

public class Shenti  extends JPanel implements MouseListener{

    DuobaoSwingLaunch game;
    Map heroMap;

    JLabel shengming;
    JLabel jingshen;
    JLabel neili;
    JLabel qianneng;
    JLabel xiuxing;
    JLabel bingqi;
    JLabel kuijia;
    JLabel peizhi;
    JLabel xiulian;

    JLabel fanhui;
    JLabel fanhuiyouxi;
    public Shenti(DuobaoSwingLaunch game)
    {
        this.game=game;
        this.heroMap=Maps.getMap(this.game.hero.getLocation());
        this.setLayout(new GridLayout(16,1,1,1));

        setShengming();
        setJingshen();
        setNeili();
        setQianneng();
        setXiuxing();
        setBingqi();
        setKuijia();
        setPeizhi();
        setXiulian();
        setFanhui();
        setFanhuiyouxi();
    }

    private void setShengming() {
        shengming=new JLabel("生命："+this.game.getHero().getHP()+"/"+this.game.getHero().getMaxHP());
        shengming.setFont(myFont.f2);
        shengming.addMouseListener(this);
        JPanel jp1=new JPanel();
        jp1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp1.add(shengming);
        this.add(jp1);

    }

    private void setJingshen() {
        jingshen=new JLabel("精神："+this.game.getHero().getSP()+"/"+this.game.getHero().getMaxSP());
        jingshen.setFont(myFont.f2);
        jingshen.addMouseListener(this);
        JPanel jp1=new JPanel();
        jp1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp1.add(jingshen);
        this.add(jp1);

    }

    private void setNeili() {
        neili=new JLabel("内力："+this.game.getHero().getMP()+"/"+this.game.getHero().getMaxMP());
        neili.setFont(myFont.f2);
        neili.addMouseListener(this);
        JPanel jp1=new JPanel();
        jp1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp1.add(neili);
        this.add(jp1);

    }

    private void setQianneng() {
        qianneng=new JLabel("潜能："+this.game.getHero().getProficiency()+"/"+this.game.getHero().getMaxProficiency());
        qianneng.setFont(myFont.f2);
        qianneng.addMouseListener(this);
        JPanel jp1=new JPanel();
        jp1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp1.add(qianneng);
        this.add(jp1);

    }

    private void setXiuxing() {
        xiuxing=new JLabel("修行："+this.game.getHero().getXiuWei());
        xiuxing.setFont(myFont.f2);
        xiuxing.addMouseListener(this);
        JPanel jp1=new JPanel();
        jp1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp1.add(xiuxing);
        this.add(jp1);
    }

    private void setBingqi() {
        bingqi=new JLabel("兵器伤害力："+this.game.getHero().getSHai());
        bingqi.setFont(myFont.f2);
        bingqi.addMouseListener(this);
        JPanel jp1=new JPanel();
        jp1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp1.add(bingqi);
        this.add(jp1);

    }

    private void setKuijia() {
        kuijia=new JLabel("盔甲保护力："+this.game.getHero().getFYu());
        kuijia.setFont(myFont.f2);
        kuijia.addMouseListener(this);
        JPanel jp1=new JPanel();
        jp1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp1.add(kuijia);
        this.add(jp1);
    }

    private void setPeizhi() {
        peizhi=new JLabel();
        peizhi.addMouseListener(this);
        peizhi.setFont(myFont.f2);
        peizhi.setForeground(Color.BLUE);
        peizhi.setText("<html><u>"+"技能配置"+"</u></html>");
        JPanel jp1=new JPanel();
        jp1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp1.add(peizhi);
        this.add(jp1);
    }

    private void setXiulian() {
        xiulian=new JLabel();
        xiulian.addMouseListener(this);
        xiulian.setFont(myFont.f2);
        xiulian.setForeground(Color.BLUE);
        xiulian.setText("<html><u>"+"修炼内力"+"</u></html>");
        JPanel jp2=new JPanel();
        jp2.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp2.add(xiulian);
        this.add(jp2);
    }

    private void setFanhui() {
        fanhui=new JLabel();
        fanhui.addMouseListener(this);
        fanhui.setFont(myFont.f2);
        fanhui.setForeground(Color.BLUE);
        fanhui.setText("<html><u>"+"返回"+"</u></html>");
        JPanel jp3=new JPanel();
        jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp3.add(fanhui);
        this.add(jp3);
    }

    private void setFanhuiyouxi() {
        fanhuiyouxi=new JLabel();
        fanhuiyouxi.addMouseListener(this);
        fanhuiyouxi.setFont(myFont.f2);
        fanhuiyouxi.setForeground(Color.BLUE);
        fanhuiyouxi.setText("<html><u>"+"返回游戏"+"</u></html>");
        JPanel jp4=new JPanel();
        jp4.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp4.add(fanhuiyouxi);
        this.add(jp4);
    }

    private boolean iFText(JLabel jl)
    {
        boolean f=true;
        if(jl==peizhi || jl==xiulian || jl==fanhui || jl==fanhuiyouxi)
        {
            f=false;
        }
        return f;
    }
    public void mouseClicked(MouseEvent e) {
        // TODO Auto-generated method stub

        if(e.getSource()==peizhi)
        {
            this.game.setPanel(new Peizhiwugong(this.game,1));
        }else if(e.getSource()==fanhuiyouxi)
        {
            this.game.setPanel(new MainPanel(this.game,1));
        }else if(e.getSource()==fanhui)
        {
            this.game.setPanel(new ZhuangTaiPanel(this.game,null,1));
        }
    }

    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub
        if(iFText((JLabel)e.getSource()))
        {
            ((JLabel)e.getSource()).setCursor(new Cursor(Cursor.TEXT_CURSOR));
        }
    }

    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    public void mousePressed(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub

    }

}
